/**
 * Copyright (c) 2013-Now http://jeesite.com All rights reserved.
 */
package com.jeesite.modules.st.web;

import com.jeesite.common.config.Global;
import com.jeesite.common.entity.Page;
import com.jeesite.common.web.BaseController;
import com.jeesite.modules.st.dao.StTakeStockDetailDao;
import com.jeesite.modules.st.entity.*;
import com.jeesite.modules.st.service.StTakeStockBillService;
import com.jeesite.modules.st.service.StWarehouseInventoryService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.List;

/**
 * st_take_stock_billController
 *
 * @author HOHD
 * @version 2021-03-09
 */
@Controller
@RequestMapping(value = "${adminPath}/st/standingBook")
public class StandingBookController extends BaseController {

    @Autowired
    private StTakeStockBillService stTakeStockBillService;

    /**
     * 获取数据
     */
    @ModelAttribute
    public StTakeStockBill get(String id, boolean isNewRecord) {
        return stTakeStockBillService.get(id, isNewRecord);
    }

    /**
     * 查询列表
     */
    @RequiresPermissions("st:stTakeStockBill:view")
    @RequestMapping(value = {"list", ""})
    public String list(StTakeStockBill stTakeStockBill, Model model) {
        model.addAttribute("stTakeStockBill", stTakeStockBill);
        return "modules/st/stTakeStockBillList";
    }

    /**
     * 查询列表
     */
    @RequiresPermissions("st:stTakeStockBill:view")
    @RequestMapping(value = {"waitChange"})
    public String waitChange(StTakeStockBill stTakeStockBill, Model model) {
        model.addAttribute("stTakeStockBill", stTakeStockBill);
        return "modules/st/stTakeStockBillList-wait-change";
    }

    /**
     * 查询列表数据
     */
    @RequiresPermissions("st:stTakeStockBill:view")
    @RequestMapping(value = "listData")
    @ResponseBody
    public Page<StTakeStockBill> listData(StTakeStockBill stTakeStockBill, HttpServletRequest request, HttpServletResponse response) {
        stTakeStockBill.setPage(new Page<>(request, response));
        Page<StTakeStockBill> page = stTakeStockBillService.findPage(stTakeStockBill);
        return page;
    }

    @Autowired
    StTakeStockDetailDao stTakeStockDetailDao;

    @RequiresPermissions("st:stTakeStockBill:view")
    @RequestMapping(value = "listWaitChangeData")
    @ResponseBody
    public Page<WaitChangeAccount> listWaitChangeData(WaitChangeAccount waitChangeAccount, HttpServletRequest request, HttpServletResponse response) {
        waitChangeAccount.setPage(new Page<>(request, response));
        Page<WaitChangeAccount> page = (Page<WaitChangeAccount>) waitChangeAccount.getPage();
        page.setList(stTakeStockDetailDao.waitChangeAccount(waitChangeAccount));
        return page;
    }
//    public Page findDetail(StProductBillBatchDetail detail) {
//        Page<StProductBillBatchDetail> page = (Page<StProductBillBatchDetail>) detail.getPage();
////	page.setPageSize(Page.PAGE_SIZE_NOT_PAGING); 	// 不分页，返回全部数据。
////	page.setCount(Page.COUNT_NOT_COUNT);  			// 不执行Count，不查询总数。
////	page.setCount(Page.COUNT_ONLY_COUNT); 			// 只Count数据，不返回数据，通过 page.getCount()获取
//        page.setList(stProductBillBatchDetailDao.findDetail(detail));
//        return page;
//    }

    /**
     * 查看编辑表单
     */
    @RequiresPermissions("st:stTakeStockBill:view")
    @RequestMapping(value = "form")
    public String form(StTakeStockBill stTakeStockBill, Model model) {
        model.addAttribute("stTakeStockBill", stTakeStockBill);
        return "modules/st/stTakeStockBillForm";
    }


    /**
     * 保存数据
     */
    @RequiresPermissions("st:stTakeStockBill:edit")
    @PostMapping(value = "save")
    @ResponseBody
    public String save(@Validated StTakeStockBill stTakeStockBill) {
        stTakeStockBillService.save(stTakeStockBill);
        return renderResult(Global.TRUE, text("保存st_take_stock_bill成功！"));
    }

    /**
     * 删除数据
     */
    @RequiresPermissions("st:stTakeStockBill:edit")
    @RequestMapping(value = "delete")
    @ResponseBody
    public String delete(StTakeStockBill stTakeStockBill) {
        stTakeStockBillService.delete(stTakeStockBill);
        return renderResult(Global.TRUE, text("删除st_take_stock_bill成功！"));
    }

}